package com.zjsru.Service.impl;

import com.zjsru.Service.UserInfoService;
import com.zjsru.dao.UserInfoMapper;
import com.zjsru.domain.UserInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;


@Service
@RequiredArgsConstructor
public class UserInfoServiceImpl implements UserInfoService {
    private final UserInfoMapper userInfoMapper;
    @Override
    public UserInfo login(String email, String password) throws LoginException{
        UserInfo userInfo=userInfoMapper.findByEmail(email);
        if(userInfo !=null){
            if (userInfo.getPassword().equals((password))) {
                if(userInfo.getStatus() == 1){
                    return userInfo;
                }else {
                    //账号未激活
                    throw new LoginException("账号未激活");
                }
            }else {
                //密码不对
                throw new LoginException("密码错误");
            }
        }else{
            //账号错误
            throw new LoginException("账号错误");
        }
    }
}
